package com.eedi.framework.dict.controller.sys.web;

import com.eedi.framework.dict.controller.sys.vo.data.SysDictDataSimpleResp;
import com.eedi.framework.dict.controller.sys.vo.data.SysDictDataDropDownResp;
import com.eedi.framework.dict.dal.dataobject.SysDictDataDO;
import com.eedi.framework.dict.service.SysDictDataService;
import com.eedi.framework.common.enums.CommonStatusEnum;
import com.eedi.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.eedi.framework.common.util.object.BeanUtils;
import javax.annotation.Resource;
import java.util.List;

import static com.eedi.framework.common.pojo.CommonResult.success;


@Tag(name = "系统界面 - 字典数据")
@RestController
@RequestMapping("/dict-data")
@Validated
public class SysDictDataController {

    @Resource
    private SysDictDataService sysDictDataService;

//    @PostMapping("/create")
//    @Operation(summary = "新增字典数据")
////    @PreAuthorize("@ss.hasPermission('sys:dict:create')")
//    public CommonResult<String> createDictData(@Valid @RequestBody SysDictDataSaveReq createReqVO) {
//        String dictDataId = sysDictDataService.createDictData(createReqVO);
//        return success(dictDataId);
//    }

//    @PutMapping("/update")
//    @Operation(summary = "修改字典数据")
////    @PreAuthorize("@ss.hasPermission('sys:dict:update')")
//    public CommonResult<Boolean> updateDictData(@Valid @RequestBody SysDictDataUpReq updateReqVO) {
//        sysDictDataService.updateDictData(updateReqVO);
//        return success(true);
//    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除字典数据")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
////    @PreAuthorize("@ss.hasPermission('sys:dict:delete')")
//    public CommonResult<Boolean> deleteDictData(String sysDictDataId) {
//        sysDictDataService.deleteDictData(sysDictDataId);
//        return success(true);
//    }

    @GetMapping(value = {"/list-all-simple", "simple-list"})
    @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地")
    // 无需添加权限认证，因为前端全局都需要
    public CommonResult<List<SysDictDataSimpleResp>> getSimpleDictDataList() {
        List<SysDictDataDO> list = sysDictDataService.getDictDataList(
                CommonStatusEnum.ENABLE, null);
        return success(BeanUtils.toBean(list, SysDictDataSimpleResp.class));
    }

//    @GetMapping("/page")
//    @Operation(summary = "/获得字典类型的分页列表")
////    @PreAuthorize("@ss.hasPermission('sys:dict:query')")
//    public CommonResult<PageResult<SysDictDataResp>> getDictTypePage(@Valid SysDictDataPageReq pageReqVO) {
//        PageResult<SysDictDataDO> pageResult = sysDictDataService.getDictDataPage(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, SysDictDataResp.class));
//    }



    @GetMapping(value = "/get")
    @Operation(summary = "/查询字典数据详细")
    @Parameter(name = "type", description = "编号", required = true, example = "1024")
    public CommonResult<List<SysDictDataDropDownResp>> getDictDataByType(String type) {
        List<SysDictDataDO> list = sysDictDataService.getDictDataList(
                CommonStatusEnum.ENABLE, type);
        return success(BeanUtils.toBean(list, SysDictDataDropDownResp.class));
    }
}
